import rcontrolutil
import rcontrol
import Tkinter

class RLabel(rcontrol.RControl):
	"""
	Label control.
	
	Properties:
	
	*text* - String. Current contents of the label. Use '&' to specify a character to be underlined. For example, if the text is set to '&hello', the h will be underlined.
	*bgcolor* - Background color of the label. RGB triplet, such as (255,0,0) for pure red.
	*color* - Foreground color of the label. RGB triplet.
	
	*enabled* - If False, the label is grayed out.
	*width* - Set width of input, where one unit is the width of a char. If set to 0, width is based on contents (the default behavior).
	*height* - Set height of input, by the height of a line of text. If set to 0, width is based on contents (the default behavior).
	
	*font* - Set font of input. Standard tkinter font format, such as ('Times New Roman', 12, 'normal')
	*wrapwidth* - Set when the text should be wrapped into multiple lines, in screen units. Default is 0 (no wrapping).
	*borderwidth* - An integer, width of border in pixels.
	*alignment* - Set alignment of text when there are multiple lines. One of 'left','right','center'.
	*borderstyle* - Border style. One of 'sunken','raised','groove','ridge','flat'. Default is 'sunken'.
	*anchor* - Set where in the button the text (or image) should be located. Provide one of the strings 'center','top','topright','right','bottomright','bottom','bottomleft','left','topleft'. Default is center.
	
	"""
	
	
	def __init__(self, strText=None, parent=None, **options):
		self._newWidgetManual(parent, Tkinter.Label)
		
		if strText!=None: self.text = strText
		self.set_many(**options)
	
	def property_enabled_get(self):
		if self._basecontrol['state']==Tkinter.DISABLED: return False
		else: return True
	def property_enabled_set(self, value):
		if value: self._basecontrol['state'] = Tkinter.NORMAL
		else: self._basecontrol['state'] = Tkinter.DISABLED
	
	def property_text_get(self):
		return rcontrolutil.underlinePositionToString(self._basecontrol['text'], self._basecontrol['underline'])
	def property_text_set(self, value):
		text, nIndex = rcontrolutil.stringToUnderlinePosition(value) # If given a string '&hello', underline the h.
		self._basecontrol.config(text=text,underline=nIndex)
	
	
	_properties = {
	
		'text':(property_text_get, property_text_set),
		'enabled':(property_enabled_get, property_enabled_set),
		
		
		'bgcolor': ('background',rcontrolutil.mapColor),
		'color': ('foreground',rcontrolutil.mapColor),
		'width': 'width',
		'height': 'height',
		'font': 'font',
		'wrapwidth': 'wraplength',
		'borderwidth': 'borderwidth',
		
		'borderstyle': ('relief',rcontrolutil.mapBorderstyle),
		'anchor': ('anchor', rcontrolutil.mapAnchor),
		'alignment': ('justify', rcontrolutil.mapAlignment),
		}
	



